<?php
    /**
     * Shop.php
     *
     * Niushop商城系统 - 团队十年电商经验汇集巨献!
     * =========================================================
     * Copy right 2015-2025 山西牛酷信息科技有限公司, 保留所有权利。
     * ----------------------------------------------
     * 官方网址: http://www.niushop.com.cn
     * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用。
     * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
     * =========================================================
     * @author : niuteam
     * @date : 2015.1.17
     * @version : v1.0.0.0
     */

    namespace data\service;

    /**
     * 交互服务层
     */
    use data\service\BaseService as BaseService;
    use data\api\ITzinvoice;
    use data\service\User;
    use data\model\SysWechatLogModel;
    use data\extend\WchatOauth;
    use data\model\TzinvoiceModel;
    use think\Config;
    use think\Log;
    use data\service\promotion\PromoteRewardRule;

    class Tzinvoice extends BaseService implements ITzinvoice
    {

        /**
         * 发票信息入库
         * @param $reqdata
         * @return bool
         */
        function saveInvoice($reqdata)
        {
            try {
                if ($reqdata) {
                    $arr = json_decode($reqdata['invoiceInfo'], true);
                }
                $user    = new User();
                $invoice = new TzinvoiceModel();
                $userInfo = $user->getUserInfo();
                $data    = [
                    'uid'             => $this->uid,
                    'openid'          => $userInfo->wx_openid,
                    'fp_tt_name'      => $arr['title'],
                    'duty'            => $arr['taxNumber'],
                    'address'         => $arr['companyAddress'],
                    'phone'           => $arr['telephone'],
                    'bank'            => $arr['bankName'],
                    'bank_num'        => $arr['bankAccount'],
                    'check_in_hotel'  => $reqdata['hotel'],
                    'name'            => $reqdata['name'],
                    'room_number'     => $reqdata['roomNumber'],
                    'the_ticket_time' => $reqdata['qpsj'],
                    'remark'          => $reqdata['remark'],
                    'create_time'     => time(),
                ];

                if ($invoice->save($data)) {
                    return true;
                }
                return false;
            }catch (\Exception $e){
                Log::write('错误码：'.$e->getCode().'错误说明：'.$e->getMessage(),'invoice-'.$userInfo->nice_name);
                return false;
            }
        }

        function getInvoice(){
            $invoice = new TzinvoiceModel();
            return $invoice->getQuery(['uid'=>$this->uid],'*','create_time DESC');
        }
    }
